package cn.sciento.transfer.infra.data.check.mapping;

import java.nio.ByteBuffer;
import cn.sciento.transfer.infra.data.check.constant.SerializeType;

public class MappedRow {
  private transient Long id;
  
  private int header;
  
  private byte[] body;
  
  public MappedRow(byte[] body) {
    this.body = body;
  }
  
  public ByteBuffer encode() {
    int size = calLength();
    int magic = SerializeType.DATA.getType() & 0xFF;
    this.header = magic << 24 | size & 0xFFFFFF;
    ByteBuffer byteBuffer = ByteBuffer.allocate(size);
    byteBuffer.putInt(this.header);
    byteBuffer.put(this.body);
    return byteBuffer;
  }
  
  public int calLength() {
    int size = 0;
    size += 4;
    size += this.body.length;
    return size;
  }
  
  public Long findId() {
    return this.id;
  }
  
  public int getHeader() {
    return this.header;
  }
  
  public byte[] getBody() {
    return this.body;
  }
  
  public Long getId() {
    return this.id;
  }
  
  public void setId(Long id) {
    this.id = id;
  }
}
